﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Gmis.IDAL;
using Gmis.DBUtility;//Please add references
namespace Gmis.SqlServerDAL
{
    /// <summary>
    /// 数据访问类:FOpen
    /// </summary>
    public partial class FOpen : IFOpen
    {
        public FOpen()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string sId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from FOpen");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Gmis.Model.FOpen model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into FOpen(");
            strSql.Append("sId,sPlan,sIncome,sExpenses,sProperty,sDebtorCreditor,sDistribution,sBear)");
            strSql.Append(" values (");
            strSql.Append("@sId,@sPlan,@sIncome,@sExpenses,@sProperty,@sDebtorCreditor,@sDistribution,@sBear)");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50),
					new SqlParameter("@sPlan", SqlDbType.NVarChar,128),
					new SqlParameter("@sIncome", SqlDbType.NVarChar,128),
					new SqlParameter("@sExpenses", SqlDbType.NVarChar,128),
					new SqlParameter("@sProperty", SqlDbType.NVarChar,128),
					new SqlParameter("@sDebtorCreditor", SqlDbType.NVarChar,128),
					new SqlParameter("@sDistribution", SqlDbType.NVarChar,128),
					new SqlParameter("@sBear", SqlDbType.NVarChar,128)};
            parameters[0].Value = model.sId;
            parameters[1].Value = model.sPlan;
            parameters[2].Value = model.sIncome;
            parameters[3].Value = model.sExpenses;
            parameters[4].Value = model.sProperty;
            parameters[5].Value = model.sDebtorCreditor;
            parameters[6].Value = model.sDistribution;
            parameters[7].Value = model.sBear;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Gmis.Model.FOpen model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update FOpen set ");
            strSql.Append("sPlan=@sPlan,");
            strSql.Append("sIncome=@sIncome,");
            strSql.Append("sExpenses=@sExpenses,");
            strSql.Append("sProperty=@sProperty,");
            strSql.Append("sDebtorCreditor=@sDebtorCreditor,");
            strSql.Append("sDistribution=@sDistribution,");
            strSql.Append("sBear=@sBear");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sPlan", SqlDbType.NVarChar,128),
					new SqlParameter("@sIncome", SqlDbType.NVarChar,128),
					new SqlParameter("@sExpenses", SqlDbType.NVarChar,128),
					new SqlParameter("@sProperty", SqlDbType.NVarChar,128),
					new SqlParameter("@sDebtorCreditor", SqlDbType.NVarChar,128),
					new SqlParameter("@sDistribution", SqlDbType.NVarChar,128),
					new SqlParameter("@sBear", SqlDbType.NVarChar,128),
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = model.sPlan;
            parameters[1].Value = model.sIncome;
            parameters[2].Value = model.sExpenses;
            parameters[3].Value = model.sProperty;
            parameters[4].Value = model.sDebtorCreditor;
            parameters[5].Value = model.sDistribution;
            parameters[6].Value = model.sBear;
            parameters[7].Value = model.sId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string sId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from FOpen ");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string sIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from FOpen ");
            strSql.Append(" where sId in (" + sIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Gmis.Model.FOpen GetModel(string sId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 sId,sPlan,sIncome,sExpenses,sProperty,sDebtorCreditor,sDistribution,sBear from FOpen ");
            strSql.Append(" where sId=@sId ");
            SqlParameter[] parameters = {
					new SqlParameter("@sId", SqlDbType.VarChar,50)};
            parameters[0].Value = sId;

            Gmis.Model.FOpen model = new Gmis.Model.FOpen();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["sId"] != null && ds.Tables[0].Rows[0]["sId"].ToString() != "")
                {
                    model.sId = ds.Tables[0].Rows[0]["sId"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sPlan"] != null && ds.Tables[0].Rows[0]["sPlan"].ToString() != "")
                {
                    model.sPlan = ds.Tables[0].Rows[0]["sPlan"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sIncome"] != null && ds.Tables[0].Rows[0]["sIncome"].ToString() != "")
                {
                    model.sIncome = ds.Tables[0].Rows[0]["sIncome"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sExpenses"] != null && ds.Tables[0].Rows[0]["sExpenses"].ToString() != "")
                {
                    model.sExpenses = ds.Tables[0].Rows[0]["sExpenses"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sProperty"] != null && ds.Tables[0].Rows[0]["sProperty"].ToString() != "")
                {
                    model.sProperty = ds.Tables[0].Rows[0]["sProperty"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sDebtorCreditor"] != null && ds.Tables[0].Rows[0]["sDebtorCreditor"].ToString() != "")
                {
                    model.sDebtorCreditor = ds.Tables[0].Rows[0]["sDebtorCreditor"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sDistribution"] != null && ds.Tables[0].Rows[0]["sDistribution"].ToString() != "")
                {
                    model.sDistribution = ds.Tables[0].Rows[0]["sDistribution"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sBear"] != null && ds.Tables[0].Rows[0]["sBear"].ToString() != "")
                {
                    model.sBear = ds.Tables[0].Rows[0]["sBear"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select sId,sPlan,sIncome,sExpenses,sProperty,sDebtorCreditor,sDistribution,sBear ");
            strSql.Append(" FROM FOpen ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" sId,sPlan,sIncome,sExpenses,sProperty,sDebtorCreditor,sDistribution,sBear ");
            strSql.Append(" FROM FOpen ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "FOpen";
            parameters[1].Value = "sId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

